﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.MountAndBlade.View.Tableaus.BasicCharacterTableau
// Assembly: TaleWorlds.MountAndBlade.View, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 61152EB8-513B-4D4A-8AC0-0D1465C6CF6C
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\Modules\Native\bin\Win64_Shipping_Client\TaleWorlds.MountAndBlade.View.dll

using System;
using System.Collections.Generic;
using System.Globalization;
using TaleWorlds.Core;
using TaleWorlds.DotNet;
using TaleWorlds.Engine;
using TaleWorlds.Engine.Options;
using TaleWorlds.InputSystem;
using TaleWorlds.Library;

#nullable disable
namespace TaleWorlds.MountAndBlade.View.Tableaus
{
  public class BasicCharacterTableau
  {
    private bool _isVersionCompatible;
    private const int _expectedCharacterCodeVersion = 4;
    private bool _initialized;
    private int _tableauSizeX;
    private int _tableauSizeY;
    private float RenderScale = 1f;
    private float _cameraRatio;
    private List<string> _equipmentMeshes;
    private List<bool> _equipmentHasColors;
    private List<bool> _equipmentHasGenderVariations;
    private List<bool> _equipmentHasTableau;
    private uint _clothColor1;
    private uint _clothColor2;
    private MatrixFrame _mountSpawnPoint;
    private MatrixFrame _initialSpawnFrame;
    private Scene _tableauScene;
    private SkinMask _skinMeshesMask;
    private bool _isFemale;
    private string _skeletonName;
    private string _characterCode;
    private Equipment.UnderwearTypes _underwearType;
    private string _mountMeshName;
    private string _mountCreationKey;
    private string _mountMaterialName;
    private uint _mountManeMeshMultiplier;
    private ArmorComponent.BodyMeshTypes _bodyMeshType;
    private ArmorComponent.HairCoverTypes _hairCoverType;
    private ArmorComponent.BeardCoverTypes _beardCoverType;
    private ArmorComponent.BodyDeformTypes _bodyDeformType;
    private string _mountSkeletonName;
    private string _mountIdleAnimationName;
    private string _mountHarnessMeshName;
    private string _mountReinsMeshName;
    private string[] _maneMeshNames;
    private bool _mountHarnessHasColors;
    private bool _isFirstFrame;
    private float _faceDirtAmount;
    private float _mainCharacterRotation;
    private bool _isVisualsDirty;
    private bool _isRotatingCharacter;
    private bool _isEnabled;
    private int _race;
    private readonly GameEntity[] _currentCharacters;
    private readonly GameEntity[] _currentMounts;
    private int _currentEntityToShowIndex;
    private bool _checkWhetherEntitiesAreReady;
    private BodyProperties _bodyProperties = BodyProperties.Default;
    private BannerCode _bannerCode;

    public Texture Texture { get; private set; }

    public bool IsVersionCompatible => this._isVersionCompatible;

    private TableauView View => this.Texture?.TableauView;

    public BasicCharacterTableau()
    {
      this._isFirstFrame = true;
      this._isVisualsDirty = false;
      this._bodyProperties = BodyProperties.Default;
      this._currentCharacters = new GameEntity[2];
      this._currentCharacters[0] = (GameEntity) null;
      this._currentCharacters[1] = (GameEntity) null;
      this._currentMounts = new GameEntity[2];
      this._currentMounts[0] = (GameEntity) null;
      this._currentMounts[1] = (GameEntity) null;
    }

    public void OnTick(float dt)
    {
      if (this._isEnabled && this._isRotatingCharacter)
        this.UpdateCharacterRotation((int) Input.MouseMoveX);
      this.View?.SetDoNotRenderThisFrame(false);
      if (this._isFirstFrame)
      {
        this.FirstTimeInit();
        this._isFirstFrame = false;
      }
      if (this._isVisualsDirty)
      {
        this.RefreshCharacterTableau();
        this._isVisualsDirty = false;
      }
      if (!this._checkWhetherEntitiesAreReady)
        return;
      int index = (this._currentEntityToShowIndex + 1) % 2;
      bool flag = true;
      if (!this._currentCharacters[this._currentEntityToShowIndex].CheckResources(true, true))
        flag = false;
      if (!this._currentMounts[this._currentEntityToShowIndex].CheckResources(true, true))
        flag = false;
      if (!flag)
      {
        this._currentCharacters[this._currentEntityToShowIndex].SetVisibilityExcludeParents(false);
        this._currentMounts[this._currentEntityToShowIndex].SetVisibilityExcludeParents(false);
        this._currentCharacters[index].SetVisibilityExcludeParents(true);
        this._currentMounts[index].SetVisibilityExcludeParents(true);
      }
      else
      {
        this._currentCharacters[this._currentEntityToShowIndex].SetVisibilityExcludeParents(true);
        this._currentMounts[this._currentEntityToShowIndex].SetVisibilityExcludeParents(true);
        this._currentCharacters[index].SetVisibilityExcludeParents(false);
        this._currentMounts[index].SetVisibilityExcludeParents(false);
        this._checkWhetherEntitiesAreReady = false;
      }
    }

    private void UpdateCharacterRotation(int mouseMoveX)
    {
      if (!this._initialized || this._skeletonName == null)
        return;
      this._mainCharacterRotation += (float) mouseMoveX * 0.005f;
      MatrixFrame initialSpawnFrame = this._initialSpawnFrame;
      initialSpawnFrame.rotation.RotateAboutUp(this._mainCharacterRotation);
      this._currentCharacters[0].SetFrame(ref initialSpawnFrame);
      this._currentCharacters[1].SetFrame(ref initialSpawnFrame);
    }

    private void SetEnabled(bool enabled)
    {
      this._isEnabled = enabled;
      this.View?.SetEnable(this._isEnabled);
    }

    public void SetTargetSize(int width, int height)
    {
      this._isRotatingCharacter = false;
      if (width <= 0 || height <= 0)
      {
        this._tableauSizeX = 10;
        this._tableauSizeY = 10;
      }
      else
      {
        this.RenderScale = NativeOptions.GetConfig(NativeOptions.NativeOptionsType.ResolutionScale) / 100f;
        this._tableauSizeX = (int) ((double) width * (double) this.RenderScale);
        this._tableauSizeY = (int) ((double) height * (double) this.RenderScale);
      }
      this._cameraRatio = (float) this._tableauSizeX / (float) this._tableauSizeY;
      this.View?.SetEnable(false);
      this.View?.AddClearTask(true);
      this.Texture?.ReleaseNextFrame();
      this.Texture = TableauView.AddTableau(nameof (BasicCharacterTableau), new RenderTargetComponent.TextureUpdateEventHandler(this.CharacterTableauContinuousRenderFunction), (object) this._tableauScene, this._tableauSizeX, this._tableauSizeY);
      this.View.SetScene(this._tableauScene);
      this.View.SetSceneUsesSkybox(false);
      this.View.SetDeleteAfterRendering(false);
      this.View.SetContinuousRendering(true);
      this.View.SetDoNotRenderThisFrame(true);
      this.View.SetClearColor(0U);
      this.View.SetFocusedShadowmap(true, ref this._initialSpawnFrame.origin, 1.55f);
      this.View.SetRenderWithPostfx(true);
      this.SetCamera();
    }

    public void OnFinalize()
    {
      this.View?.SetEnable(false);
      this.View?.AddClearTask();
      this.Texture = (Texture) null;
      this._bannerCode = (BannerCode) null;
      if (!((NativeObject) this._tableauScene != (NativeObject) null))
        return;
      this._tableauScene = (Scene) null;
    }

    public void DeserializeCharacterCode(string code)
    {
      if (!(code != this._characterCode))
        return;
      if (this._initialized)
        this.ResetProperties();
      this._characterCode = code;
      string[] strArray = code.Split('|');
      int result1;
      if (int.TryParse(strArray[0], out result1) && 4 == result1)
      {
        this._isVersionCompatible = true;
        int num = 0;
        try
        {
          int index1 = num + 1;
          this._skeletonName = strArray[index1];
          int index2 = index1 + 1;
          Enum.TryParse<SkinMask>(strArray[index2], false, out this._skinMeshesMask);
          int index3 = index2 + 1;
          bool.TryParse(strArray[index3], out this._isFemale);
          int index4 = index3 + 1;
          this._race = int.Parse(strArray[index4]);
          int index5 = index4 + 1;
          Enum.TryParse<Equipment.UnderwearTypes>(strArray[index5], false, out this._underwearType);
          int index6 = index5 + 1;
          Enum.TryParse<ArmorComponent.BodyMeshTypes>(strArray[index6], false, out this._bodyMeshType);
          int index7 = index6 + 1;
          Enum.TryParse<ArmorComponent.HairCoverTypes>(strArray[index7], false, out this._hairCoverType);
          int index8 = index7 + 1;
          Enum.TryParse<ArmorComponent.BeardCoverTypes>(strArray[index8], false, out this._beardCoverType);
          int index9 = index8 + 1;
          Enum.TryParse<ArmorComponent.BodyDeformTypes>(strArray[index9], false, out this._bodyDeformType);
          int index10 = index9 + 1;
          float.TryParse(strArray[index10], NumberStyles.Any, (IFormatProvider) CultureInfo.InvariantCulture, out this._faceDirtAmount);
          int index11 = index10 + 1;
          BodyProperties.FromString(strArray[index11], out this._bodyProperties);
          int index12 = index11 + 1;
          uint.TryParse(strArray[index12], out this._clothColor1);
          int index13 = index12 + 1;
          uint.TryParse(strArray[index13], out this._clothColor2);
          this._equipmentMeshes = new List<string>();
          this._equipmentHasColors = new List<bool>();
          this._equipmentHasGenderVariations = new List<bool>();
          this._equipmentHasTableau = new List<bool>();
          for (EquipmentIndex equipmentIndex = EquipmentIndex.NumAllWeaponSlots; equipmentIndex < EquipmentIndex.ArmorItemEndSlot; ++equipmentIndex)
          {
            int index14 = index13 + 1;
            this._equipmentMeshes.Add(strArray[index14]);
            int index15 = index14 + 1;
            bool result2;
            bool.TryParse(strArray[index15], out result2);
            this._equipmentHasColors.Add(result2);
            int index16 = index15 + 1;
            bool result3;
            bool.TryParse(strArray[index16], out result3);
            this._equipmentHasGenderVariations.Add(result3);
            index13 = index16 + 1;
            bool result4;
            bool.TryParse(strArray[index13], out result4);
            this._equipmentHasTableau.Add(result4);
          }
          int index17 = index13 + 1;
          this._mountSkeletonName = strArray[index17];
          int index18 = index17 + 1;
          this._mountMeshName = strArray[index18];
          int index19 = index18 + 1;
          this._mountCreationKey = strArray[index19];
          int index20 = index19 + 1;
          this._mountMaterialName = strArray[index20];
          int index21 = index20 + 1;
          if (strArray[index21].Length > 0)
            uint.TryParse(strArray[index21], out this._mountManeMeshMultiplier);
          else
            this._mountManeMeshMultiplier = 0U;
          int index22 = index21 + 1;
          this._mountIdleAnimationName = strArray[index22];
          int index23 = index22 + 1;
          this._mountHarnessMeshName = strArray[index23];
          int index24 = index23 + 1;
          bool.TryParse(strArray[index24], out this._mountHarnessHasColors);
          int index25 = index24 + 1;
          this._mountReinsMeshName = strArray[index25];
          int index26 = index25 + 1;
          int length = int.Parse(strArray[index26]);
          this._maneMeshNames = new string[length];
          for (int index27 = 0; index27 < length; ++index27)
          {
            ++index26;
            this._maneMeshNames[index27] = strArray[index26];
          }
        }
        catch (Exception ex)
        {
          this.ResetProperties();
          Debug.FailedAssert("Exception: " + ex.Message, "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.MountAndBlade.View\\Tableaus\\BasicCharacterTableau.cs", nameof (DeserializeCharacterCode), 348);
          Debug.FailedAssert("Couldn't parse character code: " + code, "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.MountAndBlade.View\\Tableaus\\BasicCharacterTableau.cs", nameof (DeserializeCharacterCode), 349);
        }
      }
      this._isVisualsDirty = true;
    }

    private void ResetProperties()
    {
      this._skeletonName = string.Empty;
      this._skinMeshesMask = SkinMask.NoneVisible;
      this._isFemale = false;
      this._underwearType = Equipment.UnderwearTypes.NoUnderwear;
      this._bodyMeshType = ArmorComponent.BodyMeshTypes.Normal;
      this._hairCoverType = ArmorComponent.HairCoverTypes.None;
      this._beardCoverType = ArmorComponent.BeardCoverTypes.None;
      this._bodyDeformType = ArmorComponent.BodyDeformTypes.Medium;
      this._faceDirtAmount = 0.0f;
      this._bodyProperties = BodyProperties.Default;
      this._clothColor1 = 0U;
      this._clothColor2 = 0U;
      this._equipmentMeshes?.Clear();
      this._equipmentHasColors?.Clear();
      this._mountSkeletonName = string.Empty;
      this._mountMeshName = string.Empty;
      this._mountCreationKey = string.Empty;
      this._mountMaterialName = string.Empty;
      this._mountManeMeshMultiplier = uint.MaxValue;
      this._mountIdleAnimationName = string.Empty;
      this._mountHarnessMeshName = string.Empty;
      this._mountReinsMeshName = string.Empty;
      this._maneMeshNames = (string[]) null;
      this._mountHarnessHasColors = false;
      this._race = 0;
      this._isVersionCompatible = false;
      this._characterCode = string.Empty;
    }

    private void FirstTimeInit()
    {
      if ((NativeObject) this._tableauScene == (NativeObject) null)
      {
        this._tableauScene = Scene.CreateNewScene(enable_decals: false);
        this._tableauScene.SetName(nameof (BasicCharacterTableau));
        this._tableauScene.DisableStaticShadows(true);
        SceneInitializationData initData = new SceneInitializationData(true)
        {
          InitPhysicsWorld = false,
          DoNotUseLoadingScreen = true
        };
        this._tableauScene.Read("inventory_character_scene", ref initData);
        this._tableauScene.SetShadow(true);
        this._mountSpawnPoint = this._tableauScene.FindEntityWithTag("horse_inv").GetGlobalFrame();
        this._initialSpawnFrame = this._tableauScene.FindEntityWithTag("agent_inv").GetGlobalFrame();
        this._tableauScene.EnsurePostfxSystem();
        this._tableauScene.SetDofMode(false);
        this._tableauScene.SetMotionBlurMode(false);
        this._tableauScene.SetBloom(true);
        this._tableauScene.SetDynamicShadowmapCascadesRadiusMultiplier(0.31f);
        this._tableauScene.RemoveEntity(this._tableauScene.FindEntityWithTag("agent_inv"), 99);
        this._tableauScene.RemoveEntity(this._tableauScene.FindEntityWithTag("horse_inv"), 100);
        this._currentCharacters[0] = GameEntity.CreateEmpty(this._tableauScene, false);
        this._currentCharacters[1] = GameEntity.CreateEmpty(this._tableauScene, false);
        this._currentMounts[0] = GameEntity.CreateEmpty(this._tableauScene, false);
        this._currentMounts[1] = GameEntity.CreateEmpty(this._tableauScene, false);
      }
      this.SetEnabled(true);
      this._initialized = true;
    }

    private static void ApplyBannerTextureToMesh(Mesh armorMesh, Texture bannerTexture)
    {
      if (!((NativeObject) armorMesh != (NativeObject) null))
        return;
      Material copy = armorMesh.GetMaterial().CreateCopy();
      copy.SetTexture(Material.MBTextureType.DiffuseMap2, bannerTexture);
      uint materialShaderFlagMask = (uint) copy.GetShader().GetMaterialShaderFlagMask("use_tableau_blending");
      ulong shaderFlags = copy.GetShaderFlags();
      copy.SetShaderFlags(shaderFlags | (ulong) materialShaderFlagMask);
      armorMesh.SetMaterial(copy);
    }

    private void RefreshCharacterTableau()
    {
      if (!this._initialized)
        return;
      this._currentEntityToShowIndex = (this._currentEntityToShowIndex + 1) % 2;
      GameEntity currentCharacter = this._currentCharacters[this._currentEntityToShowIndex];
      currentCharacter.ClearEntityComponents(true, true, true);
      GameEntity currentMount = this._currentMounts[this._currentEntityToShowIndex];
      currentMount.ClearEntityComponents(true, true, true);
      this._mainCharacterRotation = 0.0f;
      if (!string.IsNullOrEmpty(this._skeletonName))
      {
        AnimationSystemData forHumanSkeleton = AnimationSystemData.GetHardcodedAnimationSystemDataForHumanSkeleton();
        bool flag1 = (double) this._bodyProperties.Age >= 14.0 && this._isFemale;
        currentCharacter.Skeleton = MBSkeletonExtensions.CreateWithActionSet(ref forHumanSkeleton);
        MetaMesh glovesMesh = (MetaMesh) null;
        bool flag2 = this._equipmentMeshes[3].Length > 0;
        for (int index = 0; index < 5; ++index)
        {
          string equipmentMesh = this._equipmentMeshes[index];
          if (equipmentMesh.Length > 0)
          {
            bool flag3 = flag1 && this._equipmentHasGenderVariations[index];
            MetaMesh metaMesh = MetaMesh.GetCopy(flag3 ? equipmentMesh + "_female" : equipmentMesh + "_male", false, true);
            if ((NativeObject) metaMesh == (NativeObject) null)
            {
              string str = equipmentMesh;
              metaMesh = MetaMesh.GetCopy(!flag3 ? str + (flag2 ? "_slim" : "") : str + (flag2 ? "_converted_slim" : "_converted"), false, true) ?? MetaMesh.GetCopy(equipmentMesh, false, true);
            }
            if ((NativeObject) metaMesh != (NativeObject) null)
            {
              if (index == 3)
                glovesMesh = metaMesh;
              currentCharacter.AddMultiMeshToSkeleton(metaMesh);
              if (this._equipmentHasTableau[index])
              {
                for (int meshIndex = 0; meshIndex < metaMesh.MeshCount; ++meshIndex)
                {
                  Mesh currentMesh = metaMesh.GetMeshAtIndex(meshIndex);
                  Mesh mesh1 = currentMesh;
                  if ((mesh1 != null ? (!mesh1.HasTag("dont_use_tableau") ? 1 : 0) : 0) != 0)
                  {
                    Mesh mesh2 = currentMesh;
                    if ((mesh2 != null ? (mesh2.HasTag("banner_replacement_mesh") ? 1 : 0) : 0) != 0 && this._bannerCode != (BannerCode) null)
                    {
                      TableauCacheManager.Current.BeginCreateBannerTexture(this._bannerCode, (Action<Texture>) (t => BasicCharacterTableau.ApplyBannerTextureToMesh(currentMesh, t)), true);
                      break;
                    }
                  }
                }
              }
              else if (this._equipmentHasColors[index])
              {
                for (int meshIndex = 0; meshIndex < metaMesh.MeshCount; ++meshIndex)
                {
                  Mesh meshAtIndex = metaMesh.GetMeshAtIndex(meshIndex);
                  if (!meshAtIndex.HasTag("no_team_color"))
                  {
                    meshAtIndex.Color = this._clothColor1;
                    meshAtIndex.Color2 = this._clothColor2;
                    Material copy = meshAtIndex.GetMaterial().CreateCopy();
                    copy.AddMaterialShaderFlag("use_double_colormap_with_mask_texture", false);
                    meshAtIndex.SetMaterial(copy);
                  }
                }
              }
              metaMesh.ManualInvalidate();
            }
          }
        }
        currentCharacter.SetGlobalFrame(in this._initialSpawnFrame);
        SkinGenerationParams skinParams = new SkinGenerationParams((int) this._skinMeshesMask, this._underwearType, (int) this._bodyMeshType, (int) this._hairCoverType, (int) this._beardCoverType, (int) this._bodyDeformType, true, this._faceDirtAmount, flag1 ? 1 : 0, this._race, false, false);
        MBAgentVisuals.FillEntityWithBodyMeshesWithoutAgentVisuals(currentCharacter, skinParams, this._bodyProperties, glovesMesh);
        currentCharacter.Skeleton.SetAgentActionChannel(0, ActionIndexCache.Create("act_inventory_idle"));
        currentCharacter.SetEnforcedMaximumLodLevel(0);
        currentCharacter.CheckResources(true, true);
        if (this._mountMeshName.Length > 0)
        {
          currentMount.Skeleton = Skeleton.CreateFromModel(this._mountSkeletonName);
          MetaMesh copy1 = MetaMesh.GetCopy(this._mountMeshName);
          if ((NativeObject) copy1 != (NativeObject) null)
          {
            MountCreationKey mountCreationKey = MountCreationKey.FromString(this._mountCreationKey);
            MountVisualCreator.SetHorseColors(copy1, mountCreationKey);
            if (!string.IsNullOrEmpty(this._mountMaterialName))
            {
              Material fromResource = Material.GetFromResource(this._mountMaterialName);
              copy1.SetMaterialToSubMeshesWithTag(fromResource, "horse_body");
              copy1.SetFactorColorToSubMeshesWithTag(this._mountManeMeshMultiplier, "horse_tail");
            }
            currentMount.AddMultiMeshToSkeleton(copy1);
            copy1.ManualInvalidate();
            if (this._mountHarnessMeshName.Length > 0)
            {
              MetaMesh copy2 = MetaMesh.GetCopy(this._mountHarnessMeshName, false, true);
              if ((NativeObject) copy2 != (NativeObject) null)
              {
                if (this._mountReinsMeshName.Length > 0)
                {
                  MetaMesh copy3 = MetaMesh.GetCopy(this._mountReinsMeshName, false, true);
                  if ((NativeObject) copy3 != (NativeObject) null)
                  {
                    currentMount.AddMultiMeshToSkeleton(copy3);
                    copy3.ManualInvalidate();
                  }
                }
                currentMount.AddMultiMeshToSkeleton(copy2);
                if (this._mountHarnessHasColors)
                {
                  for (int meshIndex = 0; meshIndex < copy2.MeshCount; ++meshIndex)
                  {
                    Mesh meshAtIndex = copy2.GetMeshAtIndex(meshIndex);
                    if (!meshAtIndex.HasTag("no_team_color"))
                    {
                      meshAtIndex.Color = this._clothColor1;
                      meshAtIndex.Color2 = this._clothColor2;
                      Material copy4 = meshAtIndex.GetMaterial().CreateCopy();
                      copy4.AddMaterialShaderFlag("use_double_colormap_with_mask_texture", false);
                      meshAtIndex.SetMaterial(copy4);
                    }
                  }
                }
                copy2.ManualInvalidate();
              }
            }
          }
          foreach (string maneMeshName in this._maneMeshNames)
          {
            MetaMesh copy5 = MetaMesh.GetCopy(maneMeshName, false, true);
            if (this._mountManeMeshMultiplier != uint.MaxValue)
              copy5.SetFactor1Linear(this._mountManeMeshMultiplier);
            currentMount.AddMultiMeshToSkeleton(copy5);
            copy5.ManualInvalidate();
          }
          currentMount.SetGlobalFrame(in this._mountSpawnPoint);
          currentMount.Skeleton.SetAnimationAtChannel(this._mountIdleAnimationName, 0, blendInPeriod: 0.0f);
          currentMount.SetEnforcedMaximumLodLevel(0);
          currentMount.CheckResources(true, true);
        }
      }
      this._currentCharacters[this._currentEntityToShowIndex].SetVisibilityExcludeParents(false);
      this._currentMounts[this._currentEntityToShowIndex].SetVisibilityExcludeParents(false);
      int index1 = (this._currentEntityToShowIndex + 1) % 2;
      this._currentCharacters[index1].SetVisibilityExcludeParents(true);
      this._currentMounts[index1].SetVisibilityExcludeParents(true);
      this._checkWhetherEntitiesAreReady = true;
    }

    internal void SetCamera()
    {
      Camera camera = Camera.CreateCamera();
      camera.Frame = this._tableauScene.FindEntityWithTag("camera_instance").GetGlobalFrame();
      camera.SetFovVertical(0.7853982f, this._cameraRatio, 0.2f, 200f);
      this.View.SetCamera(camera);
      camera.ManualInvalidate();
    }

    public void RotateCharacter(bool value) => this._isRotatingCharacter = value;

    public void SetBannerCode(string value)
    {
      if (string.IsNullOrEmpty(value))
        this._bannerCode = (BannerCode) null;
      else
        this._bannerCode = BannerCode.CreateFrom(value);
    }

    internal void CharacterTableauContinuousRenderFunction(Texture sender, EventArgs e)
    {
      Scene userData = (Scene) sender.UserData;
      TableauView tableauView = sender.TableauView;
      if (!((NativeObject) userData == (NativeObject) null))
        return;
      tableauView.SetContinuousRendering(false);
      tableauView.SetDeleteAfterRendering(true);
    }
  }
}
